package Presentacion;

import Control.ControlTardia;
import Control.ControlEmpleado;
import Clases.Empleado;
import de.javasoft.plaf.synthetica.SyntheticaLookAndFeel;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import Clases.Tardia;
import Clases.TardiaId;
import com.csvreader.CsvWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import Clases.crearPDF;

public class Tardias extends javax.swing.JFrame {

    ControlTardia controlT = ControlTardia.obtenerInstancia();
    ControlEmpleado controlE = ControlEmpleado.obtenerInstancia();
    private ImageIcon iconoError;
    private File archivo = null;
    static ButtonGroup grupo = new ButtonGroup();
    DateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd");
    ArrayList<Tardia> TardiasActuales;

    private Tardias() {

        initComponents();
        grupo.add(jRadioButtonExcel);
        grupo.add(jRadioButtonPDF);
        jRadioButtonExcel.setSelected(true);
    }
    private static Tardias instancia = null;

    public static Tardias obtenerInstancia() {
        if (instancia == null) {
            instancia = new Tardias();
        }
        return instancia;
    }

    public void init() {
        setTitle("Reporte Tardias");
        setLocationRelativeTo(null);
        UIManager.removeAuxiliaryLookAndFeel(UIManager.getLookAndFeel());
        SwingUtilities.updateComponentTreeUI(this);
        try {
            UIManager.removeAuxiliaryLookAndFeel(UIManager.getLookAndFeel());
            SyntheticaLookAndFeel.setWindowsDecorated(false);
            UIManager.setLookAndFeel("de.javasoft.plaf.synthetica.SyntheticaAluOxideLookAndFeel");
            SwingUtilities.updateComponentTreeUI(this);

        } catch (Exception ex) {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        this.setVisible(true);
        inicioTooltops();
        jButton3.setEnabled(false);
        jButton4.setEnabled(false);
        limpiar();
    }

    private boolean validaFechas(Date inicio, Date fechaFinal) {
        boolean itsk = true;
        if (inicio == null || fechaFinal == null) {
            jLabel1.setVisible(true);
            itsk = false;

        } else if (inicio.compareTo(fechaFinal) > 0) {
            jLabel1.setVisible(true);
            itsk = false;
        }

        return itsk;
    }

    private boolean validarReporte() {
        ocultarLabels();
        boolean itsOk = true;
        if (jLabelRuta.getText() == " ") {
            jLabel7.setVisible(true);
            itsOk = false;
        }
        return itsOk;
    }

    private void inicioTooltops() {
        iconoError = new ImageIcon(getClass().getResource("/Imagenes/warning.png"));

        jLabel1.setIcon(iconoError);
        jLabel1.setToolTipText("Debe seleccionar fechas valida ");
        jLabel7.setIcon(iconoError);
        jLabel7.setToolTipText("Debe seleccionar una ruta");
        ocultarLabels();
    }

    private void limpiar() {
        jDateChooser1.setDate(null);
        jDateChooser2.setDate(null);
        DefaultTableModel m = (DefaultTableModel) jTable3.getModel();
        while (m.getRowCount() > 0) {
            m.removeRow(0);
        }
        jLabelRuta.setText(" ");
    }

    private void ocultarLabels() {

        jLabel1.setVisible(false);
        jLabel7.setVisible(false);
    }

    public void llenarTablaTardia(ArrayList<Tardia> tardias) {
        DefaultTableModel m = (DefaultTableModel) jTable3.getModel();
        m.setRowCount(0);
        Tardia temp;
        while (m.getRowCount() > 0) {
            m.removeRow(0);
        }
        for (int i = 0; i < tardias.size(); i++) {
            temp = tardias.get(i);
            long numEmpleado=tardias.get(i).getEmpleado().getNumEmpleado();
            Empleado empleado=controlE.getEmpleadoNum(numEmpleado);
            if (empleado != null) { // hace q no muestre tardias de empleados historicos
                Empleado eTemp = controlE.getEmpleadoNum(temp.getId().getNumEmpleado());
                String nombre = eTemp.getNombre() + " " + eTemp.getApellido1();
                m.insertRow(m.getRowCount(), new Object[]{nombre, eTemp.getCodigo(), temp.getHorasTarde()+" mins", temp.getId().getFecha() , temp.getJustificacion()});
            }
        }
        if (m.getRowCount() > 0) {
            jButton3.setEnabled(true);
            jButton4.setEnabled(true);

        }
    }

    void generarReporteTardia(int opc) throws IOException {
        Date fecha = new Date();
        String fechaString = dateFormat.format(fecha);
        ControlEmpleado ce = ControlEmpleado.obtenerInstancia();
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(new java.io.File("."));
        chooser.setDialogTitle("Elegir Destino");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setAcceptAllFileFilterUsed(false);

        if (opc == 1) {

            String ruta = jLabelRuta.getText() + fechaString + "_reporteTardia_" + ".csv";
            boolean existe = new File(ruta).exists();
            if (existe) {
                File ficheroUsuarios = new File(ruta);
                ficheroUsuarios.delete();
            }

            CsvWriter writer = new CsvWriter(new FileWriter(ruta, true), ';');
            try {

                writer.writeRecord(new String[]{"NombreEmpleado", "codigo", "horas tarde", "fecha"});

                for (Tardia temp : TardiasActuales) {
                    Empleado eTemp = controlE.getEmpleadoNum(temp.getId().getNumEmpleado());
                    String nombre = eTemp.getNombre() + " " + eTemp.getApellido1();

                    writer.writeRecord(new String[]{nombre, String.valueOf(eTemp.getCodigo()), String.valueOf(temp.getHorasTarde()), temp.getId().getFecha().toString()});
                }
            } catch (IOException e) {
            }
            writer.close();
            JOptionPane.showMessageDialog(null, "csv generado con toda la información del reporte de la caja dia " + String.valueOf(fecha.getDate()) + " del mes: "
                    + String.valueOf(fecha.getMonth() + 1), "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            dispose();

        } else {

            String ruta = archivo.getPath();
            crearPDF pdf = new crearPDF();
            ArrayList<String> contenidoPDF = new ArrayList<String>();
            contenidoPDF.add(" ");
            contenidoPDF.add(" ");
            contenidoPDF.add("Fecha de Reporte: " + String.valueOf(fecha.getDay()) + "/" + String.valueOf(fecha.getMonth() + 1) + "/" + String.valueOf(fecha.getYear() + 1900));
            for (Tardia temp : TardiasActuales) {
                Empleado eTemp = controlE.getEmpleadoNum(temp.getId().getNumEmpleado());
                String nombre = eTemp.getNombre() + " " + eTemp.getApellido1();
                contenidoPDF.add("Nombre del empleado: " + nombre);
                contenidoPDF.add("Código del empleado: " + eTemp.getCodigo());
                contenidoPDF.add("Horas tarde: " + String.valueOf(temp.getHorasTarde()));
                contenidoPDF.add("Fecha: " + temp.getId().getFecha().toString());
                contenidoPDF.add(" ");
                contenidoPDF.add(" ");
            }
            pdf.crearPDF(String.valueOf(fecha.getDate()) + String.valueOf(fecha.getMonth() + 1), "Tardias", contenidoPDF, ruta);
            JOptionPane.showMessageDialog(null, "PDF generado con toda la información del reporte de la tardias dia " + String.valueOf(fecha.getDate()) + " del mes: "
                    + String.valueOf(fecha.getMonth() + 1), "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            dispose();
        }

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable3 = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        jDateChooser1 = new com.toedter.calendar.JDateChooser();
        jDateChooser2 = new com.toedter.calendar.JDateChooser();
        jLabel3 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jLabelRuta = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jRadioButtonExcel = new javax.swing.JRadioButton();
        jRadioButtonPDF = new javax.swing.JRadioButton();
        jButton4 = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(560, 320));

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jTable3.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre", "Código", "Duración", "Fecha", "Justificación"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable3.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTable3KeyReleased(evt);
            }
        });
        jScrollPane3.setViewportView(jTable3);
        if (jTable3.getColumnModel().getColumnCount() > 0) {
            jTable3.getColumnModel().getColumn(1).setResizable(false);
            jTable3.getColumnModel().getColumn(4).setResizable(false);
        }

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel2.setText("Desde:");

        jDateChooser1.setDateFormatString("dd-MM-yyyy");

        jDateChooser2.setDateFormatString("dd-MM-yyyy");

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel3.setText("Hasta:");

        jButton2.setText("Buscar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel1.setText("x");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel5.setText("Reportes Tardías");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel5)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel3)
                                .addGap(30, 30, 30)
                                .addComponent(jDateChooser2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel1)))
                        .addGap(41, 41, 41)
                        .addComponent(jButton2)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jScrollPane3))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel5)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jDateChooser2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel1)
                                .addComponent(jButton2))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jDateChooser1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jButton1.setText("Salir");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel4.setText("Ruta del archivo:");

        jLabelRuta.setText("                                                         ");

        jButton3.setText("Buscar ruta");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel6.setText("Formato del reporte: ");

        jRadioButtonExcel.setText("Excel(.csv)");

        jRadioButtonPDF.setText("PDF(.pdf)");

        jButton4.setText("Crear reporte");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jLabel7.setText("x");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(82, 82, 82)
                        .addComponent(jLabelRuta, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton3)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jButton4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButtonExcel)
                            .addComponent(jLabel6)
                            .addComponent(jRadioButtonPDF))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jLabelRuta)
                    .addComponent(jButton3)
                    .addComponent(jLabel7))
                .addGap(35, 35, 35)
                .addComponent(jLabel6)
                .addGap(15, 15, 15)
                .addComponent(jRadioButtonExcel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jRadioButtonPDF)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton4))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        ocultarLabels();
        Date fechaInicio = jDateChooser1.getDate();
        Date fechaFinal = jDateChooser2.getDate();
        if (validaFechas(fechaInicio, fechaFinal)) {
            ocultarLabels();

            ArrayList<Tardia> tardias = controlT.getTardias(fechaInicio, fechaFinal);
            TardiasActuales = tardias;
            llenarTablaTardia(tardias);
            if (tardias.size() == 0) {
                JOptionPane.showMessageDialog(null, "La cantidad de tardias de este periodo de tiempo es 0", "Mensaje", JOptionPane.ERROR_MESSAGE);

            }

        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        final JFileChooser fc = new JFileChooser();
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int returnVal = fc.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            archivo = fc.getSelectedFile();
            if (archivo.isDirectory()) {

                jLabelRuta.setText(archivo.toString() + File.separator);
            }
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        if (validarReporte()) {
            if (jRadioButtonExcel.isSelected()) {
                try {
                    generarReporteTardia(1);
                } catch (IOException ex) {
                    Logger.getLogger(OpcionesReportesCaja.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else {
                try {
                    generarReporteTardia(2);
                } catch (IOException ex) {
                    Logger.getLogger(OpcionesReportesCaja.class.getName()).log(Level.SEVERE, null, ex);
                }
            }

        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jTable3KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable3KeyReleased
        DefaultTableModel m = (DefaultTableModel) jTable3.getModel();
        for (int i = 0; i < m.getRowCount(); i++) {
            String justificacion = (String) m.getValueAt(i, 4);
            if (justificacion != null) {
                Date fecha = (Date) m.getValueAt(i, 3);
                long codigoEmpleado = (Long) m.getValueAt(i, 1);
                int horasTarde = (Integer) m.getValueAt(i, 2);
                Empleado empleado = controlE.getEmpleadoCodigo(codigoEmpleado);
                TardiaId tardiaid = new TardiaId(fecha, empleado.getNumEmpleado());
                Tardia tardia = new Tardia(tardiaid, empleado, horasTarde, justificacion);
                controlT.actualizarTardia(tardia);
            }
        }
        JOptionPane.showMessageDialog(null, "Se justificaron tardia(s) con exito");
    }//GEN-LAST:event_jTable3KeyReleased

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Tardias.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Tardias.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Tardias.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Tardias.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Tardias().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private com.toedter.calendar.JDateChooser jDateChooser1;
    private com.toedter.calendar.JDateChooser jDateChooser2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabelRuta;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JRadioButton jRadioButtonExcel;
    private javax.swing.JRadioButton jRadioButtonPDF;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTable jTable3;
    // End of variables declaration//GEN-END:variables
}
